/**
 * 将数据赋值到另一个对象
 * @param {Object} target
 * @param {Object} source
 * @param {Boolean} fullMerge 默认只赋值target中存在的键，true时全赋值
 * @param {Boolean} deepMerge 是否进行深度赋值，默认只赋值第一层
 */
export function objectMerge(target, source, fullMerge = false, deepMerge = false) {
  if (!target || !source || typeof target !== 'object' || typeof source !== 'object') {
    return target
  }
  if (Array.isArray(source) || Array.isArray(target)) {
    return target
  }
  Object.keys(source).forEach(property => {
    if (fullMerge || property in target) {
      const sourceProperty = source[property]
      if (deepMerge && typeof sourceProperty === 'object' && !Array.isArray(sourceProperty)) {
        target[property] = objectMerge(target[property], sourceProperty, fullMerge, deepMerge)
      } else {
        target[property] = sourceProperty
      }
    }
  })
  return target
}

/**
 * 深度克隆
 * @param {Object} target
 * @returns {Object}
 */
export function deepClone(target) {
  if (typeof target !== 'object') return target
  return JSON.parse(JSON.stringify(target))
}


